/*
 * CS 567 GUI - Semester Project - "DecisionLists"
 * Jason Frank
 * Spring 2011
 *
 * This File:  Makes the JPanel of the a Pro or Con of a list item in Buttefly View.
 *
 */

package Decision_Lists;

import Decision_Lists.List_Item_Data.ProCon;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.LinkedList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

/*
 */
public class ProConPanel extends JPanel {

  ///////////////////////////
  ///// Class Vars //////////
  protected ProCon procon;  // the class with data about one Pro or Con
  protected Color panel_BG_color = new Color(240,240,240); // grayish-white
  protected Color parent_BG_color;  // The color that should appear on the OUTSIDE THE ROUNDED CORNERS
                                    //  (to blend in with the bg of this panel)
  protected Color bgColor = new Color(250,250,250);  // Grayish-white

  // Items to layout on this panel:
  protected JLabel mainPhrase_component = new JLabel();
  protected List <JLabel> detail_components = new LinkedList<JLabel>();


  protected Font mainPhrase_font = new    Font("Helvetica", Font.BOLD,  18);
  protected Font detail_font     = new    Font("Helvetica", Font.PLAIN, 9);

  protected int detail_width = 100;

  // Layered Pane stuff
  protected int layered_level = 0;  // to start with (for underlying rounded rectangle)
  protected JLayeredPane layeredPane = new JLayeredPane();

  ///// end Class Vars /////
  //////////////////////////

  // Constructor
  public ProConPanel(ProCon procon, Color parent_bg)  {

    mainPhrase_component.setFont(mainPhrase_font);
    this.procon = procon;          
    this.parent_BG_color = parent_bg;

    initComponents(); // Initializes the visible components with the values from the obj's pro or con
    layoutProCon();  // layout the pro or con

    // TEMP: border for debugging. TODO: remove this later? (make rounded corners instead?)
    setBorder(BorderFactory.createEtchedBorder());

    setBackground(bgColor);

  } ////// end constructor //////

  // Initializes the visible components with the values from the obj's pro or con
  protected void initComponents() {

    mainPhrase_component.setText(procon.getMainPhrase());
    // TODO: iterate through the list of details and create JLabels for each?
    //         (or should I use something more abstracted?)
    detail_components.clear();
    for (String detail : procon.getDetailsList()) {
      JLabel label = new JLabel();
      // Set the text with a max width so the text wraps around
      label.setText(String.format("<html><div style=\"width:%dpx;\">%s</div><html>", detail_width, detail));
      label.setFont(detail_font);
      detail_components.add(label);
    }
    
  } /////// end initComponents() ////////


  protected void layoutProCon() {

    Box outerBox = Box.createVerticalBox();
    outerBox.add(mainPhrase_component);

    for(JLabel detailComponent: detail_components) {
      outerBox.add(detailComponent);
      outerBox.add(Box.createRigidArea(new Dimension(0, 10)));
    }

    add(outerBox);

  } ////// end layoutProCon() ///////////




  //////////////////////////
  // TODO: add setPreferredSize, etc?  (or will it just auto-size things if I don't?)

  
} //////////////////// end class ProConPanel /////////////////////////////
